package RRHH_MODELO;

import Conexion.Conexion;
import java.sql.SQLException;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class RHH_REGIONAL {

    private double ID;
    private double REGIONAL_CONTABLE;
    private String DESCRIPCION;
    private String ACRONIMO;
    private Conexion con = null;

    public RHH_REGIONAL(Conexion con) {
        this.con = con;
    }

    public RHH_REGIONAL(double ID, String DESCRIPCION, String Acronimo) {
        this.ID = ID;
        this.DESCRIPCION = DESCRIPCION;
        this.ACRONIMO = Acronimo;
    }

    public boolean Insertar() throws SQLException {
        String consulta = "insert into BROKER.RHH_REGIONAL(ID,DESCRIPCION, ACRONIMO) VALUES (" + ID + ",'" + DESCRIPCION + "', '" + ACRONIMO + "')";
        con.EjecutarSentencia(consulta);
        return true;
    }

    public boolean EliminarXid() throws SQLException {
        String consulta = "delete from BROKER.RHH_REGIONAL where ID = " + getID();
        con.EjecutarSentencia(consulta);
        return true;
    }

    public boolean ActivarRegionalContable(Double id_regional) throws SQLException {
        String consulta = "update BROKER.RHH_REGIONAL set REGIONAL_CONTABLE = 0 where ID =" + id_regional;
        con.EjecutarSentencia(consulta);
        return true;
    }

    public boolean DesactivarRegionalContable(Double id_regional) throws SQLException {
        String consulta = "update BROKER.RHH_REGIONAL set REGIONAL_CONTABLE = 1 where ID =" + id_regional;
        con.EjecutarSentencia(consulta);
        return true;
    }

    public RHH_REGIONAL BuscarXid(double id) throws SQLException {
        String consulta = "select * from BROKER.RHH_REGIONAL where ID = " + id;
        ResultSet rs = con.EjecutarConsulta(consulta);
        List<RHH_REGIONAL> lista = Cargar(rs);
        if (lista.size() > 0) {
            return lista.get(0);
        } else {
            return null;
        }
    }

    public List<RHH_REGIONAL> TodosLosInactivos(double depto) throws SQLException {
        String consulta = "select * from BROKER.RHH_REGIONAL sp where sp.ID not in(select ID_REGIONAL from BROKER.RHH_REGIONAL_DEPTO where ID_DEPTO = " + depto + ")";
        ResultSet rs = con.EjecutarConsulta(consulta);
        return Cargar(rs);
    }

    public List<RHH_REGIONAL> Todos() throws SQLException {
        String consulta = "select * from BROKER.RHH_REGIONAL";
        ResultSet rs = con.EjecutarConsulta(consulta);
        return Cargar(rs);
    }

    public List<RHH_REGIONAL> Cargar(ResultSet rs) throws SQLException {
        List<RHH_REGIONAL> lista = new ArrayList<RHH_REGIONAL>();
        while (rs.next()) {
            RHH_REGIONAL objeto = new RHH_REGIONAL(con);
            objeto.setID(rs.getDouble("ID"));
            objeto.setREGIONAL_CONTABLE(rs.getDouble("REGIONAL_CONTABLE"));
            objeto.setDESCRIPCION(rs.getString("DESCRIPCION"));
            objeto.setACRONIMO(rs.getString("ACRONIMO"));
            objeto.setCon(con);
            lista.add(objeto);
        }
        return lista;
    }

    public double getID() {
        return ID;
    }

    public void setID(double ID) {
        this.ID = ID;
    }

    public String getDESCRIPCION() {
        return DESCRIPCION;
    }

    public void setDESCRIPCION(String DESCRIPCION) {
        this.DESCRIPCION = DESCRIPCION;
    }

    public Conexion getCon() {
        return con;
    }

    public void setCon(Conexion con) {
        this.con = con;
    }

    public String getACRONIMO() {
        return ACRONIMO;
    }

    public void setACRONIMO(String ACRONIMO) {
        this.ACRONIMO = ACRONIMO;
    }

    public double getREGIONAL_CONTABLE() {
        return REGIONAL_CONTABLE;
    }

    public void setREGIONAL_CONTABLE(double REGIONAL_CONTABLE) {
        this.REGIONAL_CONTABLE = REGIONAL_CONTABLE;
    }
}
